using System;
using System.IO;
using System.Linq;

namespace FileMapper {
    public class Id3v1: Id3 {
        public Id3v1() {}

        protected override bool CheckFormat(Stream file) {
            var position = file.Position;
            try {
                file.Seek(-128, SeekOrigin.End);
                var buffer = new byte[3];
                file.Read(buffer, 0, 3);
                return buffer.SequenceEqual(new byte[] { 0x54, 0x41, 0x47 }); // TAG
            } finally {
                file.Position = position;
            }
        }

        protected override ExtentList GetFixedExtents(Stream file) {
            var position = file.Position;
            try {
                return new ExtentList { new Extent { Offset = 0, Size = file.Length - 128 } };
            } finally {
                file.Position = position;
            }
        }
    }
}
